﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class SellMobileDetailDAL
    {
        public string connecttion = "SERVER=localhost;" +
                                    "DATABASE=sellingmobilemanagement;" +
                                    "UID=root;" +
                                    "PASSWORD= 515154; ";

        #region[SellMobileDetail_SelectALL]
        public List<DTO.SellMobileDetailDTO> SellMobileDetail_SelectALL()
        {
            List<DTO.SellMobileDetailDTO> sadall = new List<DTO.SellMobileDetailDTO>();
            
            Connection connecttion = new Connection();
            MySqlConnection con = new MySqlConnection(connecttion.Connect);
            MySqlCommand cmd = new MySqlCommand("SelectAllSellMobileDetail", con);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            con.Open();
            MySqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                DTO.SellMobileDetailDTO sad = new DTO.SellMobileDetailDTO();
                sad.SellMobileID = dr.GetInt32(0);
                sad.MobileID = dr.GetInt32(1);
                sad.Number = dr.GetInt32(2);
                sad.SellID = dr.GetInt32(3);
                sadall.Add(sad);
            }
            dr.Close();
            con.Close();

            return sadall;
        }
        #endregion

        #region [SellMobileDetail_Insert]
        public bool SellMobileDetail_Insert(DTO.SellMobileDetailDTO sad)
        {
            Connection connecttion = new Connection();
            MySqlConnection con = new MySqlConnection(connecttion.Connect);
            MySqlCommand cmd = new MySqlCommand("AddSellMobileDetail", con);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            cmd.Parameters.Add(new MySqlParameter("@mobileid", sad.MobileID));
            cmd.Parameters.Add(new MySqlParameter("@number", sad.Number));
            cmd.Parameters.Add(new MySqlParameter("@sellid", sad.SellID));

            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

            return true;
        }
        #endregion
    }
}
